﻿using System;

namespace Dyao.Book.Contract.Serialization
{
    /// <summary>
    /// 枚举字符显示
    /// </summary>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class ShowStringEnumDescriptionAttribute : SerializeFormatterAttribute
    {
        public ShowStringEnumDescriptionAttribute(Type enumType, string separator = ",", bool isIgnoreCase = true)
        {
            if (!enumType.IsEnum)
            {
                throw new ArgumentException("只接受枚举类型。", nameof(enumType));
            }

            EnumType = enumType;
            Separator = separator;
            IsIgnoreCase = isIgnoreCase;
        }

        /// <summary>
        /// 序列化描述名称格式化字符串，默认不设置。不设置时使用全局设置的格式化字符串。
        /// 格式例如：{0}_desc、StatusText（完全自定义的名称）
        /// </summary>
        public string NameFormat { get; set; }

        /// <summary>
        /// 枚举类型
        /// </summary>
        public Type EnumType { get; set; }

        /// <summary>
        /// 分隔符
        /// </summary>
        public string Separator { get; set; } = ",";

        /// <summary>
        /// 是否忽略大小写
        /// </summary>
        public bool IsIgnoreCase { get; }

        /// <summary>
        /// 展示分隔符
        /// </summary>
        public string DescSeparator { get; set; } = ",";
    }
}
